﻿<common:LayoutAwarePage
    x:Class="BingMapsGeolocationTemplate.MainPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BingMapsGeolocationTemplate"
    xmlns:data="using:BingMapsGeolocationTemplate.Data"
    xmlns:common="using:BingMapsGeolocationTemplate.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:bm="using:Bing.Maps"
    mc:Ignorable="d"
    Background="#1A9FE0">

    <Page.Resources>
        <!-- Grid-appropriate 310 by 260 pixel item template as seen in section 4 -->
        <DataTemplate x:Key="StandardItemTemplate">
            <Grid Height="30" Width="300" Margin="0,0,0,0">
                <StackPanel Margin="0,10,0,0">
                    <TextBlock Text="{Binding Title}" TextWrapping="Wrap"/>
                </StackPanel>
            </Grid>
        </DataTemplate>
        
        <!--IsSourceGrouped="true"
            ItemsPath="TopItems"-->
        
        <CollectionViewSource
            x:Name="groupedItemsViewSource"
            Source="{Binding Groups}"
            d:Source="{Binding AllGroups, Source={d:DesignInstance Type=data:PlacesDataSource, IsDesignTimeCreatable=True}}"/>

        <CollectionViewSource
            x:Name="itemsViewSource"
            Source="{Binding Items}"
            d:Source="{Binding AllGroups[0].Items, Source={d:DesignInstance Type=data:RecipeDataSource, IsDesignTimeCreatable=True}}"/>
    </Page.Resources>

    <Page.TopAppBar>
        <AppBar x:Name="GlobalAppBar" Padding="10,0,10,0" BorderThickness="0.1" Background="#1A9FE0">
            <Grid Background="#1A9FE0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50*"/>
                    <ColumnDefinition Width="50*"/>
                </Grid.ColumnDefinitions>
                <StackPanel x:Name="LeftCommands" Orientation="Horizontal" Grid.Column="0" HorizontalAlignment="Left" Background="#1A9FE0">
                    <Button x:Name="Home" AutomationProperties.Name="Home" Style="{StaticResource HomeAppBarButtonStyle}" HorizontalAlignment="Left" Click="Home_Click"/>
                </StackPanel>
                <StackPanel x:Name="RightCommands" Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right" Background="#1A9FE0">
                </StackPanel>
            </Grid>
        </AppBar>
    </Page.TopAppBar>

    <Grid Background="#1A9FE0">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>
        <bm:Map x:Name="map"  Credentials="INSERT_YOUR_BING_MAPS_KEY_HERE" Width="1000" Grid.Column="0">
            <bm:Map.Children>
                <bm:Pushpin x:Name="unifei" Tapped="UnifeiTapped">
                    <bm:MapLayer.Position>
                        <bm:Location Latitude="-22.412939" Longitude="-45.449782" />
                    </bm:MapLayer.Position>
                </bm:Pushpin>
            </bm:Map.Children>
        </bm:Map>
        <Grid Grid.Column="1" Margin="10,50,0,0">
            <Grid.RowDefinitions>
                <RowDefinition Height="80"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Grid.Row="0">
                <Button x:Name="backButton" Click="GoBack" IsEnabled="False" Style="{StaticResource SnappedBackButtonStyle}"/>
                <TextBlock x:Name="pageTitle" Text="Locais" Style="{StaticResource HeaderTextStyle}" HorizontalAlignment="Center"/>
            </StackPanel>
            <ListView x:Name="listaGrupos" Grid.Row="1"
                  ItemTemplate="{StaticResource StandardItemTemplate}"
                  ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
                  FontSize="18"
                  SelectionMode="None"
                  IsItemClickEnabled="True" ItemClick="lista_ItemClick">
            </ListView>
            <ListView x:Name="listaItems" Grid.Row="1"
                  ItemTemplate="{StaticResource StandardItemTemplate}"
                  ItemsSource="{Binding Source={StaticResource itemsViewSource}}"
                  FontSize="18" HorizontalAlignment="Center" 
                  SelectionMode="None"
                  IsItemClickEnabled="True"
                  Visibility="Collapsed" ItemClick="lista_ItemClick">
            </ListView>
        </Grid>
        
    </Grid>
</common:LayoutAwarePage>
